<?php
$rs = $this->lastResult;
$when = isEmpty(getParam("desde")) && isEmpty(getParam("hasta")) ? " hasta el día de hoy": " del ".getParam("desde")." al ".getParam("hasta");

$chequeRecha = array();
$chequeRec = array();
$chequeNoRec = array();
$chequeRechaTotal = 0;
$chequeRecTotal = 0;
$chequeNoRecTotal = 0;


$i = 0;
while($i < count($rs)){
    if($rs[$i]['STATUS'] == 2 || $rs[$i]['STATUS'] == 0){
        $chequeRecha[$i] = $rs[$i]['ID'];
        $chequeRechaTotal += $rs[$i]['MONTO'];
        if($rs[$i]['STATUS'] == 0){
            $chequeNoRec[$i] = $rs[$i]['ID'];
            $chequeNoRecTotal += $rs[$i]['MONTO'];
        }else{
            if($rs[$i]['STATUS'] == 2){
                $chequeRec[$i] = $rs[$i]['ID'];
                $chequeRecTotal += $rs[$i]['MONTO'];
            }
        }
    }
    $i++;
}
?>

<div style="width:100%; overflow:auto;">
    <input type="hidden" name="page" id="page" />
    <table  style="font-size: 10px" width="100%" border="0" cellspacing="0" class="table table-striped table-bordered table-hover" cellpadding="0">
        <thead>
            <tr>
                <th colspan="14"><legend>Cheques Rechazados<?php echo $when; ?></legend></th>
            </tr>
            <tr>
                <td>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin: 20px 0px 20px 0px" class="table table-striped table-bordered table-hover">
                        <tr>
                            <th colspan="6">Rechazados</th>
                        </tr>
                        <tr>
                            <th width="19%" align="left">Numero</th>
                            <th width="19%" align="left">Fecha</th>
                            <th width="13%" align="left" >Monto</th>
                            <th width="13%" align="left">Banco</th>
                            <th width="18%" align="left">Fecha Rechazo</th>
                            <th width="18%" align="left">Concepto</th>
                        </tr>
                        <?php foreach($chequeRecha as $ch){ 
                                $res = $this->db->query_select("cllg_cheque",sprintf("ID=%s",$ch));
                            ?>
                                <tr>
                                    <td width="19%" align="right"><?php echo $res[0]['NUMERO']?></th>
                                    <td width="19%"><?php echo $res[0]['FECHA']?></td>
                                    <td width="13%" align="right" ><?php echo number_format($res[0]['MONTO'],2)?></td>
                                    <td width="13%"><?php echo $res[0]['BANCO']?></td>
                                    <td width="18%"><?php echo $res[0]['FECHA_RECHAZO']?></td>
                                    <td width="18%"><?php echo $res[0]['CONCEPTO_RECHAZO']?></td>
                                </tr>    
                        <?php } ?>
                        <tr>
                            <td colspan="2" align="left">Total:
                            </td>
                            <td><?php echo number_format($chequeRechaTotal,2);?></td>
                            <td colspan="3">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table style="margin: 20px 0px 20px 0px" class="table table-striped table-bordered table-hover" width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <th colspan="6">Rechazados Recuperados</th>
                        </tr>
                        <tr>
                            <th width="19%" align="left">Numero</th>
                            <th width="19%" align="left">Fecha</th>
                            <th width="13%" align="left" >Monto</th>
                            <th width="13%" align="left">Banco</th>
                            <th width="18%" align="left">Fecha Rechazo</th>
                            <th width="18%" align="left">Concepto</th>
                        </tr>
                        <?php foreach($chequeRec as $ch){ 
                                $res = $this->db->query_select("cllg_cheque",sprintf("ID=%s",$ch));
                            ?>
                                <tr>
                                    <td width="19%" align="right"><?php echo $res[0]['NUMERO']?></th>
                                    <td width="19%"><?php echo $res[0]['FECHA']?></td>
                                    <td width="13%" align="right" ><?php echo number_format($res[0]['MONTO'],2)?></td>
                                    <td width="13%"><?php echo $res[0]['BANCO']?></td>
                                    <td width="18%"><?php echo $res[0]['FECHA_RECHAZO']?></td>
                                    <td width="18%"><?php echo $res[0]['CONCEPTO_RECHAZO']?></td>
                                </tr>    
                        <?php } ?>
                        <tr>
                            <td colspan="2" align="left">Total:
                            </td>
                            <td><?php echo number_format($chequeRecTotal,2);?></td>
                            <td colspan="3">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin: 20px 0px 20px 0px" class="table table-striped table-bordered table-hover">
                        <tr>
                            <th colspan="6">Rechazados No Recuperados</th>
                        </tr>
                        <tr>
                            <th width="19%" align="left">Numero</th>
                            <th width="19%" align="left">Fecha</th>
                            <th width="13%" align="left" >Monto</th>
                            <th width="13%" align="left">Banco</th>
                            <th width="18%" align="left">Fecha Rechazo</th>
                            <th width="18%" align="left">Concepto</th>
                        </tr>
                        <?php foreach($chequeNoRec as $ch){ 
                                $res = $this->db->query_select("cllg_cheque",sprintf("ID=%s",$ch));
                            ?>
                                <tr>
                                    <td width="19%" align="right"><?php echo $res[0]['NUMERO']?></th>
                                    <td width="19%"><?php echo $res[0]['FECHA']?></td>
                                    <td width="13%" align="right" ><?php echo number_format($res[0]['MONTO'],2)?></td>
                                    <td width="13%"><?php echo $res[0]['BANCO']?></td>
                                    <td width="18%"><?php echo $res[0]['FECHA_RECHAZO']?></td>
                                    <td width="18%"><?php echo $res[0]['CONCEPTO_RECHAZO']?></td>
                                </tr>    
                        <?php } ?>
                        <tr>
                            <td colspan="2" align="left">Total:
                            </td>
                            <td><?php echo number_format($chequeNoRecTotal,2);?></td>
                            <td colspan="3">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>
    </table>
</div>